/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DBLayer;

import DBLayer.Interfaces.IContainer;
import ModelLayer.Employee;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Evil
 */
public class DBEmployee extends DatabaseAccess implements IContainer<Employee>
{
    public DBEmployee()
    {
        super();
    }

    public Employee ValidateEmployee(String username, String password)
    {
        try
        {
            String query = "";

            Statement getStatement = dbConnection.createStatement();

            ResultSet results = getStatement.executeQuery(query);

            Employee employee;

            while (results.next())
            {
            }
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    private Employee buildEmployee(ResultSet results)
    {
        Employee employee = new Employee();
        try
        {
            while (results.next())
            {
                employee.setUsername(results.getString("Username"));
                employee.setPasswordHash(results.getString("Password"));
                employee.setSalary(Integer.parseInt(results.getString("Salary")));

            }
        }
        catch (SQLException e)
        {
            System.out.println(e.getErrorCode());
        }
        return employee;
    }

    public Employee getObject(int EmployeeID)
    {
        String query = "Select EmployeeID as ID, Salary, Username, Password, SecurityLevel, RoleID From Employee WHERE EmployeeID = " + EmployeeID;
        ResultSet result = ExecuteQuery(query);

        GenericModelBinder<Employee> employeeModelBinder = new GenericModelBinder<Employee>(Employee.class);

        Employee employee = null;
        try
        {
            employee = employeeModelBinder.BindModel(result);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }

        return employee;
    }


    public Employee getEmployeeByActorID(int actorID)
    {
        String query = "Select EmployeeID as ID, Role.ActorID, Salary, Username, Password, SecurityLevel, Employee.RoleID From Employee, Role Where Employee.RoleID = Role.RoleID and Role.ActorID = " + actorID;
        ResultSet result = ExecuteQuery(query);

        GenericModelBinder<Employee> modelBinder = new GenericModelBinder<Employee>(Employee.class);
        
        try
        {
            return modelBinder.BindModel(result);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }


    public ArrayList<Employee> getObjects()
    {
         String query = "Select EmployeeID as ID, Salary, Username, Password, SecurityLevel, Employee.RoleID From Employee";
         ResultSet result = ExecuteQuery(query);
         
        GenericModelBinder<Employee> modelBinder = new GenericModelBinder<Employee>(Employee.class);

        try
        {
            return modelBinder.BindModels(result);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public boolean SaveObject(Employee object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean DeleteObject(Employee object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean UpdateObject(Employee object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
